package redis1;

import redis.clients.jedis.Jedis;

import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MyRedistest {
    public static void main(String[] args) {
        final String watchkeys = "watchkeys";
        //20个线程池并发数
        ExecutorService executor = Executors.newFixedThreadPool(20);

        final Jedis jedis = new Jedis("192.168.17.128", 6379);
        //设置起始的抢购数
        jedis.set(watchkeys, "100");
        // jedis.del("setsucc", "setfail");
        jedis.close();

        //设置1000个人来发起抢购
        for (int i = 0; i < 1000; i++) {
            executor.execute(new MyRunnable("user"+ i ));
        }
        executor.shutdown();
    }


    /**
     * length是随机字符串长度
     * @param length
     * @return
     */
    public static String getRandomString(int length) {
        String base = "abcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }
}